package org.socket.api.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.socket.api.entity.ServerMessage;
import org.socket.api.repo.MessageRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;

@RestController
@RequestMapping("/server/message")
public class Message {
	
	private static Logger log = LoggerFactory.getLogger(Message.class);
	
	@Autowired
	private MessageRepo messageRepo;

	@GetMapping("/send")
	public String send(ServerMessage message) {
		message.setReceive("发送成功");
		message = messageRepo.save(message);
		log.debug(JSON.toJSONString(message));
		return JSON.toJSONString(message);
	}
	
}
